package com.itheima.youdianda.controller;

import cn.hutool.core.convert.Convert;
import com.itheima.youdianda.common.Result;
import com.itheima.youdianda.domain.YddAdvpos;
import com.itheima.youdianda.domain.YddLink;
import com.itheima.youdianda.service.YddLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.geom.RectangularShape;
import java.util.List;
import java.util.Map;

/**
 * @author Hakuna Matata
 * @date 2022-09-07-14:55
 */
@RestController
@RequestMapping("ydd_link")
public class YddLinkController {

    @Autowired
    private YddLinkService yddLinkService;

    /**
     * 链接详情
     *
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    public Result getLinkDetail(Integer id) {
        YddLink yddLink = yddLinkService.getById(id);
        return Result.ok(yddLink);
    }

    @PostMapping("update")
    public Result updateLink(@RequestBody YddLink yddLink) {
        yddLinkService.updateById(yddLink);
        return Result.ok("修改成功!");
    }

    @GetMapping("del")
    public Result delete(Integer id) {
        //String id = param.get("id");
        yddLinkService.removeById(id);
        return Result.ok("删除成功!");
    }

    @PostMapping("add")
    public Result add(@RequestBody YddLink yddLink) {
        yddLink.setDefaultData("1");
        yddLinkService.save(yddLink);
        return Result.ok("添加成功!");
    }

    @GetMapping("list")
    public Result linkList(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                             @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit,
                             String type) {
        return yddLinkService.linkList(page, limit, type);
    }

}
